package com.itaming.lycheeframework.bootstrap;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.ServiceLoader;

/**
 * 启动扩展模块环境后置处理器
 *
 * @author A.Ming
 */
public class BootstrapEnvironmentPostProcessor implements EnvironmentPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        ServiceLoader.load(EnvironmentProcessor.class)
            .stream()
            .map(ServiceLoader.Provider::get)
            .sorted(AnnotationAwareOrderComparator.INSTANCE)
            .forEach(processor -> processor.process(environment, application));
    }

}
